<?php

namespace Modules\Test\Service;

use Closure;
use Duxravel\Core\UI\Table;

class TableService extends Table
{
    /**
     * @var Table|null
     */
    private static ?Table $table = null;

    /**
     * @param $data
     * @param Closure $callback
     * @return Table|TableService|null
     */
    public static function make($data, Closure $callback){
        if(!(self::$table instanceof self)){
            self::$table = new self($data);
        }
        call_user_func($callback, self::$table);
        return self::$table;
    }

    /**
     * 显示单图
     * @param string $name
     * @param string $field
     * @param int|string $width
     * @param int|string $height
     */
    public function showImage(string $name, string $field, $width = 40, $height = 40){
        self::$table->column($name,$field)->node([
            'nodeName'=>'a-image',
            'vBind:src'=>'rowData.record.'.$field,
            'width'=> $width,
            'height'=> $height
        ]);
    }

}
